<?php


use Illuminate\Console\Command;
use Carbon\Carbon;

class OrderRecycle extends Command {

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'order:recycle';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'recyle expire order';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct() {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function fire() {
    	Log::info("recyle the expire orders");
    	Log::error("command execute order recycle");
    	//查询60分钟内没有支付的订单
    	Log::info(Carbon::now()->subHour());
    	$orders = Order::where('created_at','<',Carbon::now()->subHour())->where('status','=',0)->get();
    	$orders->each(function($order){
    		//回收订单
    		$order->recycle(array('status' => 4));
    	});
    	//Log::info("expire order size is ".count($orders));
    }

    /**
     * Get the console command arguments.
     *
     * @return array
     */
    protected function getArguments() {
        return array();
    }

    /**
     * Get the console command options.
     *
     * @return array
     */
    protected function getOptions() {
        return array();
    }

}
